<?php

namespace App\Http\Controllers\Home;

use App\Models\Users;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class AuthController extends Controller
{
    public function loginView(Request $request)
    {
        $ip = $request->getClientIp();
        $user = Users::where('ip', $ip)->first();
        if (is_null($user) || empty($user)) {
            return redirect()->away('https://www.baidu.com');
        }
        return view('home.login');
    }

    public function login(Request $request)
    {
        $ip = $request->getClientIp();
        $user = Users::where('ip', $ip)->where('name', $request->name)->first();
        if (is_null($user) || empty($user)) {
            return redirect()->away('https://www.baidu.com');
        }
        return view('home.index')->with(compact('user'));
    }
}
